package com.example.wangfanwangluo.wangfanboss;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wangfanwangluo.wangfanboss.Adapters.KucunDetailAdapter;
import com.example.wangfanwangluo.wangfanboss.Models.KucunDetailModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanghouyi on 2017/11/27.
 */

public class KucunDetailActivity extends AppCompatActivity {

    private String title;
    private ListView lv;
    private KucunDetailAdapter adapter;
    private List<KucunDetailModel> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_kucun_detail);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        ActionBar actionbar = getSupportActionBar();
        if (actionbar != null){
            actionbar.hide();
        }
        Intent intent = getIntent();
        this.title = intent.getStringExtra("title");

        //标题
        changeTitle();

        //返回按钮
        backAction();
        //数据
        loadData();
        //视图，传递数据
        initViews();
    }


    private void loadData() {
        for (int i = 1; i <= 20; i++) {
            if (i % 2 == 1) {
                KucunDetailModel firstModel = new KucunDetailModel(String.valueOf(i),"JHFENRNXCJ1232124","待发货","100","水杯",
                        "200","100","50");
                list.add(firstModel);
            }else {
                KucunDetailModel secondModel = new KucunDetailModel(String.valueOf(i),"GHJHFFJFJ3211322","已配载","200","衣服",
                        "300","200","100");
                list.add(secondModel);
            }

        }
    }

    private void initViews() {
        TextView iconView = (TextView)findViewById(R.id.kucun_detail_header_icon);
        String icon;
        if (this.title.equals("今日库存")) {
            icon = getResources().getString(R.string.kucun);
        }else if (this.title.equals("今日开单")) {
            icon = getResources().getString(R.string.kaidan);
        }else if (this.title.equals("之前库存")) {
            icon = getResources().getString(R.string.lastkucun);
        }else {
            icon = getResources().getString(R.string.peizai);
        }
        iconView.setText(icon);

        TextView titleView = (TextView)findViewById(R.id.kucun_detail_header_title);
        String titleString = this.title + "(120单)";
        titleView.setText(titleString);

        TextView infoView = (TextView)findViewById(R.id.kucun_detail_header_info);
        String infoString = "合计：运费" + "380" + "元   " + "1000" + "吨，" + "1000" + "方，" +
                "1000" + "件";
        infoView.setText(infoString);

        //listview
        adapter = new KucunDetailAdapter(this,list);
        lv = (ListView)findViewById(R.id.kucun_detail_listview);
        lv.setAdapter(adapter);
        adapter.setObjOnDetailPushListener(new KucunDetailAdapter.onDetailPushListener() {
            @Override
            public void onDetailPushListener(int i) {
                //进入详情页面
                Intent intent = new Intent(KucunDetailActivity.this,DocumentDetail.class);
                Bundle bundle = new Bundle();
                bundle.putString("type", "detail");
                intent.putExtras(bundle);     //将bundle传入intent中。
                startActivity(intent);
                Toast.makeText(KucunDetailActivity.this,"第" + i + "条item被点击", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void changeTitle() {
        TextView textView = (TextView)findViewById(R.id.kucun_detail_title);
        textView.setText(this.title);
    }

    public void backAction(){
        TextView textView = (TextView)findViewById(R.id.exitbtn_kucun_detail);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}
